<template>
  <div>
    <el-card shadow="always">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-input
            clearable
            maxlength="50"
            v-model="query.search"
            placeholder="请输入联系人/联系方式"
          ></el-input>
        </el-col>
        <el-col :span="4">
          <el-input
            clearable
            maxlength="50"
            v-model="query.unitName"
            placeholder="请输入单位名称"
          ></el-input>
        </el-col>
        <el-col :span="4">
          <el-select v-model="query.state" >
            <el-option
              v-for="item in [
                {
                  value: '0',
                  label: '正常',
                },
           
                {
                  value: '2',
                  label: '已联系',
                },
                {
                  value: '3',
                  label: '已完成',
                },
              ]"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="2">
          <el-button
            type="primary"
            @click="
              getList();
              query.page = 1;
            "
            >查询</el-button
          ></el-col
        >
      </el-row>
      <rz-height></rz-height>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="unitName" label="招标单位"></el-table-column>
        <el-table-column prop="tenderTime" label="投标时间"></el-table-column>
        <el-table-column
          prop="inviteTendersName"
          label="招标名称"
        ></el-table-column>
        <el-table-column
          prop="contacts"
          label="联系人"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="contactInformation"
          label="联系电话"
          width="150"
        ></el-table-column>
        <el-table-column prop="contactInformation" label="状态" width="150">
          <template slot-scope="scope">
            <div v-if="scope.row.stateStr == '已撤销'" class="red">
              {{ scope.row.stateStr }}
            </div>
            <div v-else class="green">{{ scope.row.stateStr }}</div>
          </template>
        </el-table-column>
          <el-table-column
          prop="createTime"
          label="提交日期"
          width="180"
        ></el-table-column>
        <el-table-column label="操作" width="280">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              @click="seeInspect(scope.row, 1)"
              v-if="scope.row.stateStr == '正常'"
              >编辑</el-button
            >
            <el-button size="mini" @click="seeInspect(scope.row, 2)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :total="total"
        @pagination="getList"
        :page.sync="query.page"
      />
    </el-card>

    <el-dialog
      title="登录"
      :visible.sync="dialogVisible"
      width="400px"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :show-close="false"
    >
      <el-form ref="form" :model="form" label-width="0" :rules="rules">
        <el-form-item prop="mobile">
          <el-input
            v-model="form.mobile"
            maxlength="11"
            placeholder="请输入手机号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="cipher">
          <el-input
            v-model="form.cipher"
            type="password"
            placeholder="请输入密码"
            maxlength="18"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit" style="width: 100%"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      title="查看/编辑"
      :visible.sync="dialogVisibleView"
      width="50%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :show-close="false"
    >
      <el-form ref="form" :model="viewData" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="招标单位">
              {{ viewData.unitName }}
            </el-form-item>
          </el-col>
            <el-col :span="12">
            <el-form-item label="招标名称">
              {{ viewData.inviteTendersName }}
            </el-form-item>
          </el-col>
      
        </el-row>

        <el-row >
          <el-col :span="12" v-if="index == 1"> 
            <el-form-item label="状态">
              <el-select v-model="state">
                <el-option
                  v-for="item in [
                    {
                      value: 2,
                      label: '已联系',
                    },
                    {
                      value: 3,
                      label: '已完成',
                    },
                  ]"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
           <el-col :span="12" v-else>
            <el-form-item label="状态">
              <div v-if="viewData.stateStr == '已撤销'" class="red">
              {{ viewData.stateStr }}
            </div>
            <div v-else class="green">{{viewData.stateStr }}</div>
            </el-form-item>
          </el-col>
              <el-col :span="12">
            <el-form-item label="投标时间">
              {{ viewData.tenderTime }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
        
          <el-col :span="12">
            <el-form-item label="联系人">
              {{ viewData.contacts }}
            </el-form-item>
          </el-col>
           <el-col :span="12">
            <el-form-item label="联系电话">
              {{ viewData.contactInformation }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
         
          <el-col :span="12">
            <el-form-item label="邀约单位所在地">
              {{ viewData.result }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="邀约标段">
              <div v-for="(item, index) in viewData.tenderLotList" :key="index">
                <span>标段{{ index + 1 }}</span> {{ item.lotContent }}
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleView = false">关 闭</el-button>
        <el-button type="primary" v-if="index == 1" @click="saveSubmit"
          >保 存</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  landSupplierPromotionForm,
  findTenderList,
  findTenderById,
  updateTenderStateById,
} from "@/api/modules/enterprise";
import Vue from "vue";
export default {
  // props:[],
  // 页面加载
  created() {
    // this.getList();
    if (this.$formValidate && this.$formValidate.mobile) {
      this.dialogVisible = false;
      landSupplierPromotionForm({
        params: this.$formValidate,
      }).then((res) => {
        this.getList();
      });
    }
  },
  // 页面加载完成
  mounted() {},
  //实例销毁之前
  beforeDestroy() {},
  //实例销毁后
  destroyed() {},
  data() {
    return {
      query: {
        isPage: 0,
        page: 1,
        pageSize: 10,
        search: "",
        state: "0",
        unitName: "",
      },
      tableData: [],
      total: 0,
      dialogVisible: true,
      form: {
        mobile: "",
        cipher: "",
      },
      rules: {
        mobile: [{ required: true, message: "请输入手机号", trigger: "blur" }],
        cipher: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      viewData: {},
      dialogVisibleView: false,
      index: 1,
      state:2,
    };
  },
  // 方法
  methods: {
    getList() {
      landSupplierPromotionForm({
        params: this.$formValidate,
      }).then((res) => {
        findTenderList(this.query).then((res) => {
          this.tableData = res.data.list;
          this.total = res.totalCount;
        });
      });
    },
    async seeInspect(e, index) {
      landSupplierPromotionForm({
        params: this.$formValidate,
      }).then(async (res) => {
        let { data } = await findTenderById({
          params: {
            id: e.id,
          },
        });
        if (data.tenderLocationList.some((x) => x.districtCode == "320500")) {
          data.result = "苏州市";
        } else {
          data.result = data.tenderLocationList
            .map((x) => x.districtName)
            .join(",");
        }
        this.viewData = data;
        this.dialogVisibleView = true;
        this.index = index;
      });
    },
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          landSupplierPromotionForm({
            params: this.form,
          }).then((res) => {
            this.$success(res.msg);
            Vue.prototype.$formValidate = this.form;
            this.getList();
            this.dialogVisible = false;
          });
        }
      });
    },
    saveSubmit() {
      landSupplierPromotionForm({
        params: this.$formValidate,
      }).then((res) => {
        updateTenderStateById({
          params: {
            id: this.viewData.id,
            state: this.state,
          },
        }).then((res) => {
          this.dialogVisibleView = false;
          this.getList();
        });
      });
    },
  },
  // 监听属性
  watch: {},
  // 组件
  components: {},
  // 计算属性
  computed: {},
};
</script>

<style lang="scss" scoped>
</style>